package cqut.gbq.qimo.controller;

import cqut.gbq.qimo.entity.RegisterUser;
import cqut.gbq.qimo.entity.ResBean;
import cqut.gbq.qimo.entity.Student;
import cqut.gbq.qimo.entity.Teacher;
import cqut.gbq.qimo.service.StudentsService;
import cqut.gbq.qimo.service.TeacherService;
import cqut.gbq.qimo.utils.MD5Utils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName RegisterController
 * @Description TODO
 * @Author guobenqi
 * @Date 2021/6/17 16:52
 */
@Api(tags = "注册相关")
@RestController
public class RegisterController {
    @Autowired
    private StudentsService studentsService;

    @Autowired
    private TeacherService teacherService;


    @ApiOperation("注册相关")
    @PostMapping("/register")
    public ResBean register(@RequestBody RegisterUser registerUser){
        System.out.println(registerUser);

        String password = MD5Utils.MD5(registerUser.getPassword());
        if (registerUser.getType().equals("teacher")){
           return teacherService.register(registerUser.getUsername(),password,registerUser.getSchool(),registerUser.getName());




        }else{
          return studentsService.register(registerUser.getUsername(),password,registerUser.getSchool(),registerUser.getName(),registerUser.getUid());

        }

//        return ResBean.success("注册失败");

    }
}
